package com.hzz.dao.dsync;

import com.hzz.framework.dao.IBaseDao;
import com.hzz.framework.entity.IEntity;
import org.apache.ibatis.annotations.*;

/**
 * <p>系统_云端同步 数据库处理接口类。
 */
@Mapper
public interface IDSyncDao extends IBaseDao {
    /**
     * 判断是否存在
     */
    @Override
    @Select("select IFNULL(count(0),0) as count from dsync where  id = #{id} ")
    int isDataExist(IEntity entity) throws Exception;

    @Update("update dsync set date_updated=now() ,version=version+1  ,state = #{state} , result = #{result} where id = #{id} ")
    int updateStateById(IEntity entity) throws Exception;
    /**
     * 判断是否存在
     */
    @Select("select IFNULL(count(0),0) as count from dsync where  djson = #{djson} ")
    int isDataExistByDJson(IEntity entity) throws Exception;

    @Update("update dsync set date_updated=now() ,version=version+1  ,state = #{state} , result = #{result} where djson = #{djson} ")
    int updateStateByDJson(IEntity entity) throws Exception;

    /**
     * 根据主键 物理删除
     */
    @Override
    @Delete("delete from dsync where id = #{id} ")
    int deleteByPrimaryKey(IEntity entity) throws Exception;

    /**
     * 根据过期天数 物理删除
     */
    @Delete("delete from dsync where IFNULL(datediff(DATE_FORMAT(now(),'%Y%m%d'),DATE_FORMAT(date_created,'%Y%m%d')),999)>#{expireDay} ")
    int deleteByExpireDay(@Param("expireDay") Integer expireDay) throws Exception;

    /**
     * 删除已同步日志
     */
    @Delete("delete from dsync where state = 1 ")
    int deleteByState() throws Exception;
}
